package com.ruix.app.widget.clip;


import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.widget.RelativeLayout;

/**
 * User: Ray
 * Date: 15/10/10
 * ReadMe: 图片裁剪－移动缩放－自定义view
 */
public class ClipImageLayout extends RelativeLayout {

    private ClipZoomImageView mZoomImageView;
        private ClipRectImageBorderView mClipImageView;// 矩形截取
//    private ClipRoundImageBorderView mClipImageView;// 圆形截取
    private int mHorizontalPadding = 60;

    public ClipImageLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        //ClipRectImageBorderView

        mZoomImageView = new ClipZoomImageView(context);
        mClipImageView = new ClipRectImageBorderView(context);// 矩形截取
//        mClipImageView = new ClipRoundImageBorderView(context);// 圆形截取

        android.view.ViewGroup.LayoutParams lp = new LayoutParams(
                android.view.ViewGroup.LayoutParams.MATCH_PARENT,
                android.view.ViewGroup.LayoutParams.MATCH_PARENT);

        this.addView(mZoomImageView, lp);
        this.addView(mClipImageView, lp);


        // 计算padding的px
        mHorizontalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mHorizontalPadding, getResources().getDisplayMetrics());
        mZoomImageView.setHorizontalPadding(mHorizontalPadding);
        mClipImageView.setHorizontalPadding(mHorizontalPadding);
    }

    /**
     * 对外公布设置边距的方法,单位为dp
     *
     * @param mHorizontalPadding
     */
    public void setHorizontalPadding(int mHorizontalPadding) {
        this.mHorizontalPadding = mHorizontalPadding;
    }

    /**
     * 裁切图片
     *
     * @return
     */
    public Bitmap clip() {
        return mZoomImageView.clip();
    }

    public void setBitmap(Bitmap bitmap) {
        mZoomImageView.setImageBitmap(bitmap);
    }

}
